import httpFetch from "share/httpFetch";
import config from "config";
import errorMessage from "share/errorMessage";

export default {
  //得到发票袋审核与未审核数量
  getBagCount() {
    return httpFetch
      .get(`/api/expense/reports/bag/finance/query`)
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

  //得到发票袋列表
  getBagList(page, size, param) {
    return httpFetch
      .post(
        `/api/expense/reports/bag/finance/query?page=${page}&size=${size}`,
        param
      )
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

  //根据发票袋id得到发票袋内的员工发票
  getInvoiceListByBagId(id) {
    return httpFetch
      .get(`/api/invoice/receipt/finance/query/${id}`)
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

  //根据发票袋id得到发票袋内的费用列表
  getExpenseListByBagId(id) {
    return httpFetch.get(`/api/invoice/finance/query/${id}`).catch((e) => {
      errorMessage(e.response);
      throw e;
    });
  },

  //得到发票袋头
  getBagDetail(id) {
    return httpFetch
      .get(`/api/expense/reports/bag/finance/detail/${id}`)
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

  //根据发票袋id得到发票袋内的报销单列表
  getReportListByBagId(id) {
    return httpFetch
      .get(`/api/expense/reports/finance/query/${id}`)
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

  //批量查验
  batchVerify(invoices) {
    return httpFetch
      .post(`/receipt/api/receipt/recheck`, invoices)
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

  //批量审核通过
  batchPass(expenseReportBagId, approvalText) {
    return httpFetch
      .post(`/api/expense/reports/bag/audit/pass`, {
        expenseReportBagId,
        approvalText,
      })
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

  //批量审核拒绝
  batchReject(expenseReportBagId, approvalText) {
    return httpFetch
      .post(`/api/expense/reports/bag/audit/reject`, {
        expenseReportBagId,
        approvalText,
      })
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

  //批量删除发票
  batchDeleteInvoice(params) {
    return httpFetch
      .delete(`/receipt/api/receipts/delete`, params)
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

  //批量更改发票核对状态
  batchCheckInvoice(params) {
    return httpFetch.post(`/api/mark/receipt/tag`, params).catch((e) => {
      errorMessage(e.response);
      throw e;
    });
  },

  //删除发票
  deleteInvoice(receiptId) {
    return httpFetch.delete(`/receipt/api/receipts/${receiptId}`).catch((e) => {
      errorMessage(e.response);
      throw e;
    });
  },

  //得到发票详情
  getInvoiceDetail(receiptId) {
    return httpFetch.get(`/api/receipt/query/${receiptId}`).catch((e) => {
      errorMessage(e.response);
      throw e;
    });
  },

  //OCR扫描发票图片
  scanBase64(imageData, bagId) {
    return httpFetch
      .post(`/api/expense/reports/bag/receipt/scan`, {
        imageData,
        entityType: "bag",
        entityId: bagId,
      })
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

  //自动审核
  autoAudit(bagId) {
    return httpFetch
      .post(
        `/api/finance/autoAudit/manual/audit?bagId=${bagId}&auditType=1002`,
        {},
        {
          "Content-Type": "application/x-www-form-urlencoded",
        }
      )
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

  //查询是否开启自动查验
  canAutoAudit(companyOid) {
    return httpFetch
      .get(`/api/finance/autoAudit/has/company/rule`, { companyOid })
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

  //核对发票
  checkInvoices(invoiceBagId) {
    return httpFetch
      .put(`/api/expense/reports/bag/receipt/check/batch/${invoiceBagId}`)
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

  // 发票袋扫码
  scanInvoiceBag(params) {
    return httpFetch
      .post(`/api/expense/reports/bag/audit/scancode`, params)
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

  // 发票袋审核页面是否显示加签按钮
  checkBagAddSign(bagId) {
    return httpFetch.post(
      `/api/expense/report/bag/add/sign/check?bagId=${bagId}`
    );
  },

  // 获取审核加签人列表
  getAuditSignList(entityId, entityType) {
    return httpFetch.get(`/api/authorization/policy/finance/countersign/user`, {
      entityId,
      entityType,
    });
  },

  // 发票袋向前加签
  bagCounterSign(params) {
    return httpFetch.post(`/api/expense/report/bag/countersign`, params);
  },
};
